package colin.project.sso.server.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.concurrent.ScheduledExecutorFactoryBean;

import java.util.concurrent.ScheduledExecutorService;

/**
 * @Author joker
 * @Title InvocationBeanConfig
 * @Description
 * @Date 2019/5/22 9:02 PM
 * @Since
 * @Version 1.0.0
 */
@Configuration
public class InvocationBeanConfig {

    @Value("${schedule.task.awaitTerminationSeconds}")
    private int awaitTerminationSeconds;

    @Bean(name = "scheduledExecutor")
    public ScheduledExecutorService configScheduledExecutorService() {
        ScheduledExecutorFactoryBean scheduledExecutorFactoryBean = new ScheduledExecutorFactoryBean();
        scheduledExecutorFactoryBean.setPoolSize(1);
        scheduledExecutorFactoryBean.setDaemon(true);
        scheduledExecutorFactoryBean.setContinueScheduledExecutionAfterException(true);
        scheduledExecutorFactoryBean.setAwaitTerminationSeconds(awaitTerminationSeconds);
        return scheduledExecutorFactoryBean.getObject();
    }
}
